package com.attcatstudy.cas;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author attcat
 * ---做一个有趣的程序员
 * @date 2022-11-02 19:27
 * @description
 */
public class AtomicIntegerTest{
    static AtomicInteger Atomicsum = new AtomicInteger(0);

    static Integer sum = new Integer(0);

    public static void main(String[] args) {
        for(int i=0;i<10;i++){
            Thread thread=new Thread(()->{
                for(int j=0;j<10000;j++){
                    sum++;
                    int a=Atomicsum.getAndIncrement();
                    Atomicsum.compareAndSet(a,a+1);
//                   Atomicsum.incrementAndGet();
                }

            });
            thread.start();
        }

        try{
            Thread.sleep(3000);
        } catch (InterruptedException e) { e.printStackTrace();
        }
        System.out.println(sum);
        System.out.println(Atomicsum);



    }
}
